project(hssudoku)
cmake_minimum_required(VERSION 2.6)

if(CMAKE_CROSSCOMPILING)
  set(QT_HEADERS_DIR "/usr/i486-mingw32/include")
  set(QT_LIBRARY_DIR "/usr/i486-mingw32/lib")
endif(CMAKE_CROSSCOMPILING)

if (NOT CMAKE_BUILD_TYPE)
    set ( CMAKE_BUILD_TYPE Release )
endif (NOT CMAKE_BUILD_TYPE)

if (CMAKE_BUILD_TYPE MATCHES [Dd]ebug)
    message(STATUS "Debug build")
    add_definitions(-DDEBUG)
else()
    message(STATUS "non-debug build")
    add_definitions(-DNDEBUG)
    add_definitions(-DQT_NO_DEBUG_OUTPUT)
endif()

if (NOT CMAKE_INSTALL_PREFIX)
	set(CMAKE_INSTALL_PREFIX /usr)
endif(NOT CMAKE_INSTALL_PREFIX)
message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")

set(MAJOR_VERSION 0)
set(MINOR_VERSION 1)
set(PATCH_VERSION 0)
set(HSSUDOKU_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION})
add_definitions(-DHSSUDOKU_VERSION=\"${HSSUDOKU_VERSION}\")
message(STATUS "")
message(STATUS "HsSudoku version: ${HSSUDOKU_VERSION}")
message(STATUS "")

find_package(Qt4 REQUIRED)

include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})

configure_file (
  "${PROJECT_SOURCE_DIR}/hssudokuconfigure.h.in"
  "${PROJECT_BINARY_DIR}/hssudokuconfigure.h"
  )

set(hssudoku_SRCS help-browser/helpbrowser.cpp optionsdialog.cpp scoredata.cpp resultdialog.cpp scoredialog.cpp sudokutable.cpp sudokuitem.cpp sudokuitemwidget.cpp hssudoku.cpp main.cpp)
set(hssudoku_UIS mainwindow.ui scoredlg.ui resultdlg.ui optionsdlg.ui help-browser/helpform.ui)
set(hssudoku_QRCS resources.qrc)

qt4_automoc(${hssudoku_SRCS})
QT4_WRAP_UI(header_UIS ${hssudoku_UIS})
QT4_ADD_RESOURCES(QRC_SOURCES ${hssudoku_QRCS})

add_executable(hssudoku WIN32 ${hssudoku_SRCS} ${header_UIS} ${QRC_SOURCES})
target_link_libraries(hssudoku ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})

install(TARGETS hssudoku RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(FILES hssudoku.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
install(FILES icons/hssudoku.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps)
install(DIRECTORY doc/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/${CMAKE_PROJECT_NAME}/html PATTERN "*~" EXCLUDE)
install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/${CMAKE_PROJECT_NAME})

########## Add make dist target ################
set(CPACK_PACKAGE_VERSION "${HSSUDOKU_VERSION}")
set(CPACK_SOURCE_GENERATOR "TBZ2")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${HSSUDOKU_VERSION}")
set(CPACK_IGNORE_FILES "/CVS/;/\\\\.git\;/\\\\.svn/;\\\\.swp$;\\\\.#;/#;\\\\.tar.gz$;/CMakeFiles/;CMakeCache.txt;build/;dist/;exp/;config/;.*~;build-win32/;exp-win32/;install-win32/;*.ico")
set(CPACK_SOURCE_IGNORE_FILES ${CPACK_IGNORE_FILES})
include(CPack)
# simulate autotools' "make dist"
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
